package redis

import (
	"github.com/gomodule/redigo/redis"
	"time"
)

const SERVER = "172.20.0.15:6379"

var pool *redis.Pool

func init() {
	pool = &redis.Pool{
		MaxIdle: 3,
		IdleTimeout: 240 * time.Second,
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", SERVER)
		},
	}

}

func Do(commandName string, args ...interface{}) (interface{}, error) {
	return pool.Get().Do(commandName, args...)
}

func Set(args ...interface{}) (bool, error) {
	reply, err := pool.Get().Do("SET", args...)
	if reply == "OK" {
		return true, err
	}
	return false, err
}

func GetString(key string) (data string, err error) {
	data, err = redis.String(pool.Get().Do("GET", key))
	return
}